'use strict'

const titbit = require('titbit')
const {cookie,session} = require('titbit-toolkit')

const app = new titbit({
    debug:true
})

app.use(async(c,next) => {
    if(c.query.key !== '12345') {
        return c.status(403).send('deny')
    }
    await next()
},{group:'session'})

app.use(async (c,next) => {
    console.log('time start')
    let startTime = Date.now()
    await next()
    let endTime = Date.now()
    console.log(endTime - startTime,'ms')
})

app.use(new cookie).use(new session)

app.use(async(c,next) => {
    console.log('home start')
    await next()
    console.log('home end')
},{group:'home',method:['GET']})

app.get('/',async c => {
    c.send('ok')
},{name:'主页',group:'home'})

app.get('/sess/:x/:y',async c => {
    c.setSession('x',c.param.x)  
    c.setSession('y',c.param.y)
    
    c.send( c.getSession() )

},{group:'session'})


app.run(1222)
